TitleWindow = 
{
    loadTimer = 0,
    
    FADE_IN_TIME = 1.0,
    
    
    LOAD_ANIM_TIME = 2.5, 
}



function TitleWindow.Initialize()

    -- Set the Background Texture Dimensions according to the resolution
    if( SystemData.screenResolution.x / SystemData.screenResolution.y > 1.5 ) then
        -- widescreen ratio: 1440x900
        DynamicImageSetTextureDimensions( "TitleWindowBackground", 1280, 720 )
    else
        -- normal ratio: 1024x768
        DynamicImageSetTextureDimensions( "TitleWindowBackground", 1024, 768 )
    end 
    
    WindowRegisterEventHandler( "TitleWindow", SystemData.Events.TITLE_SCREEN_INIT_LOADING_UI, "TitleWindow.BeginLoadSequence" )
    
    
    LabelSetText( "TitleWindowLoadingScreenLegalText",   GetPregameString( StringTables.Pregame.TEXT_WAR_LEGAL ) )
    WindowSetShowing( "TitleWindowLoadingScreen", false )
    
    LabelSetText( "TitleWindowLoadingText", wstring.upper( GetPregameString( StringTables.Pregame.LABEL_LOADING ) ) )
    WindowSetShowing( "TitleWindowLoadingText", false )
    
    local x, y = WindowGetDimensions( "TitleWindowLoadingScreenLegalText" )
    ERROR(L"-> Legal Text: "..x..L", "..y )
    
end

function TitleWindow.Shutdown()
end

function TitleWindow.Update( timePassed )

    if( TitleWindow.loadTimer ~= 0 )
    then
        TitleWindow.loadTimer = TitleWindow.loadTimer - timePassed
        if( TitleWindow.loadTimer <= 0 )
        then            
            TitleWindow.loadTimer = 0
            
            BroadcastEvent( SystemData.Events.TITLE_SCREEN_INIT_LOADING_UI_COMPLETE )
        end
    end

end

function TitleWindow.BeginLoadSequence()
    
    -- Fade in the Loading Frame    
    WindowSetShowing( "TitleWindowLoadingScreen", true )
    WindowStartAlphaAnimation( "TitleWindowLoadingScreen", Window.AnimationType.SINGLE, 0, 1, 
            TitleWindow.FADE_IN_TIME, true, 0, 0 )
            
    TitleWindow.loadTimer = TitleWindow.LOAD_ANIM_TIME
    
    -- Fade in the LOADING text after a delay
    WindowSetShowing( "TitleWindowLoadingText", true )
    WindowStartAlphaAnimation( "TitleWindowLoadingText", Window.AnimationType.SINGLE, 0, 1, 
            TitleWindow.FADE_IN_TIME, true, TitleWindow.FADE_IN_TIME, 0 )
end